# adjust the load path and load the plugin_test_helper
$:.unshift(File.dirname(__FILE__) + '/../lib')
$:.unshift(File.dirname(__FILE__))
require 'rubygems'
require 'plugin_test_helper.rb'
require 'network_stubs.rb'
require 'file_stub.rb'
require 'exception_inspector.rb'

# load the database schema
schema_file = File.dirname(__FILE__) + "/app_root/db/schema.rb"
load(schema_file) if File.exist?(schema_file)

class Test::Unit::TestCase
  # simulate a controller
  @@session, @@params = {}, {}

  def session; @@session; end
  def params;  @@params;  end
  def logger; RAILS_DEFAULT_LOGGER; end

  def initial_setup(login = 'admin')
    $SYNC_CONFIG = begin
      ActiveRecord::Base.load_config
    rescue => e
      RAILS_DEFAULT_LOGGER.error "Error reading configuration from database. Probably no tables found yet. Migrations?"
      {}
    end
    session[:user] = User.current_user = User.find_by_login(login.to_s)
    @request.session[:user] = session[:user] if @request && @request.session
  end
end